package com.maple.visit;

import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr;
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
import com.alibaba.druid.sql.ast.statement.SQLSelect;
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitorAdapter;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * 访问所有节点
 *
 * @author maple
 * @version 1.0
 * @since 2020-11-27 00:25
 */
@Getter
public class AllNodeVisitor extends MySqlASTVisitorAdapter {

    private final List<String> tableNameList = new ArrayList<>();

    @Override
    public boolean visit(SQLSelectStatement x) {
        System.out.println("SQLSelectStatement");
        return super.visit(x);
    }

    @Override
    public boolean visit(SQLSelect x) {
        System.out.println("SQLSelect");
        return super.visit(x);
    }

    @Override
    public boolean visit(MySqlSelectQueryBlock x) {
        System.out.println("MySqlSelectQueryBlock");
        return super.visit(x);
    }

    @Override
    public boolean visit(SQLSelectItem x) {
        System.out.println("SQLSelectItem");
        return super.visit(x);
    }

    @Override
    public boolean visit(SQLExprTableSource x) {
        System.out.println("SQLExprTableSource");
        tableNameList.add(x.getName().getSimpleName());
        return super.visit(x);
    }

    @Override
    public boolean visit(SQLBinaryOpExpr x) {
        System.out.println("SQLBinaryOpExpr");
        return super.visit(x);
    }

    @Override
    public boolean visit(SQLAllColumnExpr x) {
        System.out.println("SQLAllColumnExpr");
        return super.visit(x);
    }

    @Override
    public boolean visit(SQLIdentifierExpr x) {
        System.out.println("SQLIdentifierExpr");
        return super.visit(x);
    }

    @Override
    public boolean visit(SQLCharExpr x) {
        System.out.println("SQLCharExpr");
        return super.visit(x);
    }
}
